package com.lwl.service.impl.scl;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lwl.dao.scl.TSclRecordDetailsMapper;
import com.lwl.dao.scl.TSclRecordMapper;
import com.lwl.entity.MyPage;
import com.lwl.entity.scl.RecordMsg;
import com.lwl.entity.scl.StatisticsMsg;
import com.lwl.entity.scl.TSclRecord;
import com.lwl.entity.scl.TSclRecordDetails;
import com.lwl.service.scl.TSclRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * (TSclRecord)表服务实现类
 *
 * @author makejava
 * @since 2022-10-31 01:30:37
 */
@Service
public class TSclRecordServiceImpl implements TSclRecordService {
   @Autowired
   private TSclRecordMapper tSclRecordMapper;
   @Autowired
   private TSclRecordDetailsMapper tSclRecordDetailsMapper;

   @Override
   public Boolean checkTel(TSclRecord tSclRecord) {
      int i = tSclRecordMapper.selectCount(tSclRecord);
      return i==0;
   }

   @Override
   public int addRecord(TSclRecord tSclRecord) {
      tSclRecord.setCreatetime(new Date());

      int insert = tSclRecordMapper.insert(tSclRecord);
      System.out.println(tSclRecord.getId());

      return tSclRecord.getId();
   }

   @Override
   public PageInfo queryAll(MyPage myPage, RecordMsg recordMsg) {
      PageHelper.startPage(myPage.getPage(),myPage.getLimit());
      List<RecordMsg> recordMsgs = tSclRecordMapper.queryAll(recordMsg);
      PageInfo pageInfo = new PageInfo(recordMsgs);
      return pageInfo;
   }

   @Override
   public PageInfo queryDetails(MyPage myPage, Integer id) {
      PageHelper.startPage(myPage.getPage(),myPage.getLimit());
      List<Map<String,Object>> listmap = tSclRecordMapper.queryDetails(id);
      PageInfo pageInfo = new PageInfo(listmap);
      return pageInfo;
   }

   @Override
   public PageInfo statistics(MyPage myPage, StatisticsMsg statisticsMsg) {
      PageHelper.startPage(myPage.getPage(),myPage.getLimit());
      List<StatisticsMsg> statistics = tSclRecordMapper.statistics(statisticsMsg);
      PageInfo pageInfo = new PageInfo(statistics);
      return pageInfo;
   }

   @Override
   public Boolean delRecord(Integer id) {
      int i=-1;
      TSclRecordDetails tSclRecordDetails = new TSclRecordDetails();
      tSclRecordDetails.setRecordid(id);
      int i1 = tSclRecordDetailsMapper.selectCount(tSclRecordDetails);
      System.out.println("该用户写了"+i1+"道题SCL");
      if (i1!=90){
         i = tSclRecordMapper.deleteByPrimaryKey(id);
      }
      return i>0?true:false;
   }
}
